/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Client.java
 *
 * Created on Dec 2, 2011, 6:49:39 PM
 */
package healthcare;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*; 
/**
 *
 * @author John
 */
public class ClientPanel extends javax.swing.JPanel {

    /** Creates new form Client */
    public ClientPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        choice1 = new java.awt.Choice();
        jLabel2 = new javax.swing.JLabel();
        ClientSsnTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        FirstNameTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        MiddleInitTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        LastNameTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        StreetTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        CityTextField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        StateTextField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        ZipcodeTextField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        PhoneTextField = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        SexTextField = new javax.swing.JTextField();
        EmailTextField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        SaveButton = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        InsuranceTable = new javax.swing.JTable();
        viewInsurance = new javax.swing.JButton();
        AddInsurance = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        ScheduledVisitsTable = new javax.swing.JTable();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel13 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        findSsnTextField = new javax.swing.JTextField();
        FindButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        CreateButton = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 216, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jLabel2.setText("SSN");

        ClientSsnTextField.setEditable(false);
        ClientSsnTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClientSsnTextFieldActionPerformed(evt);
            }
        });

        jLabel3.setText("First Name");

        FirstNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FirstNameTextFieldActionPerformed(evt);
            }
        });

        jLabel4.setText("Middle Initial");

        MiddleInitTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MiddleInitTextFieldActionPerformed(evt);
            }
        });

        jLabel5.setText("Last Name");

        LastNameTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LastNameTextFieldActionPerformed(evt);
            }
        });

        jLabel6.setText("Street");

        StreetTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StreetTextFieldActionPerformed(evt);
            }
        });

        jLabel7.setText("City");

        CityTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CityTextFieldActionPerformed(evt);
            }
        });

        jLabel8.setText("State");

        StateTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StateTextFieldActionPerformed(evt);
            }
        });

        jLabel9.setText("Zip");

        ZipcodeTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ZipcodeTextFieldActionPerformed(evt);
            }
        });

        jLabel10.setText("Phone");

        PhoneTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PhoneTextFieldActionPerformed(evt);
            }
        });

        jLabel11.setText("Sex");

        SexTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SexTextFieldActionPerformed(evt);
            }
        });

        EmailTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EmailTextFieldActionPerformed(evt);
            }
        });

        jLabel12.setText("Email");

        SaveButton.setText("Save");
        SaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveButtonActionPerformed(evt);
            }
        });

        jButton2.setText("Done");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        InsuranceTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Insurance", "Account#", "Case Worker", "Phone"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        InsuranceTable.setFillsViewportHeight(true);
        jScrollPane3.setViewportView(InsuranceTable);

        viewInsurance.setText("View Insurance");
        viewInsurance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewInsuranceActionPerformed(evt);
            }
        });

        AddInsurance.setText("Add Insurance");
        AddInsurance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddInsuranceActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(viewInsurance)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(AddInsurance)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(viewInsurance)
                    .addComponent(AddInsurance))
                .addGap(57, 57, 57))
        );

        jTabbedPane1.addTab("Insurance", jPanel2);

        ScheduledVisitsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Date", "CG Name", "CG Id", "Care Type", "Invoice"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        ScheduledVisitsTable.setFillsViewportHeight(true);
        jScrollPane4.setViewportView(ScheduledVisitsTable);

        jButton8.setText("Schedule Visit");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("View Visit Detail");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton8)
                    .addComponent(jButton9))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Scheduled Visits", jPanel1);

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel13.setText("Client Details");

        jLabel15.setText("SSN");

        findSsnTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findSsnTextFieldActionPerformed(evt);
            }
        });

        FindButton.setText("Find");
        FindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FindButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Manage Client");

        CreateButton.setText("Create");
        CreateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CreateButtonActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel14.setText("Related Information");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel16.setText("Client Search");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel11)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel13))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(SexTextField)
                                    .addComponent(PhoneTextField)
                                    .addComponent(ClientSsnTextField)
                                    .addComponent(MiddleInitTextField)
                                    .addComponent(LastNameTextField)
                                    .addComponent(StreetTextField)
                                    .addComponent(CityTextField)
                                    .addComponent(StateTextField)
                                    .addComponent(ZipcodeTextField)
                                    .addComponent(FirstNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                                    .addComponent(EmailTextField)
                                    .addComponent(SaveButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(31, 31, 31)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel14)
                                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 505, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 773, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel16)
                            .addComponent(jLabel15))
                        .addGap(10, 10, 10)
                        .addComponent(findSsnTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(FindButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CreateButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel16)
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FindButton)
                    .addComponent(jLabel15)
                    .addComponent(CreateButton)
                    .addComponent(findSsnTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ClientSsnTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(FirstNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(MiddleInitTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(LastNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(StreetTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(CityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(StateTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(ZipcodeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(PhoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(SexTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)))
                    .addComponent(jTabbedPane1, 0, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SaveButton)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Insurance");
    }// </editor-fold>//GEN-END:initComponents

private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
// TODO add your handling code here:
    //validation

    String clientSsn = ClientSsnTextField.getText();
    
    if (clientSsn == null || clientSsn.length() == 0) {
        JOptionPane.showMessageDialog(this, "SSN is required", "Notice",  JOptionPane.PLAIN_MESSAGE);
    } else {
        ClientSsnTextField.setEditable(false);  //prevent editing of SSN in form

        //package form data into Client object
        Client client = new Client();
        client.CLIENTSSN	=  ClientSsnTextField.getText();	
        client.FIRSTNAME	=  FirstNameTextField.getText();	
        client.MIDDLEINIT	=  (MiddleInitTextField.getText() + " ").substring(0,1);
        client.LASTNAME         =  LastNameTextField.getText();	
        client.STREET           =  StreetTextField.getText();	
        client.CITY		=  CityTextField.getText();		
        client.STATE            =  StateTextField.getText();		
        client.PHONE            =  PhoneTextField.getText();		
        client.SEX		=  (SexTextField.getText() + " ").substring(0,1);  //filter all but first character		 
        client.EMAIL            =  EmailTextField.getText();		
        client.ZIPCODE          =  ZipcodeTextField.getText();	

        try {
            if (Database.selectClient(clientSsn) == null) {  //does record exist in DB?
                Database.insertClient(client);
                JOptionPane.showMessageDialog(this, "Client added to database", "Notice",  JOptionPane.PLAIN_MESSAGE);
            } else {
                Database.updateClient(client);
                JOptionPane.showMessageDialog(this, "Client updated in database", "Notice",  JOptionPane.PLAIN_MESSAGE);
            }
        } catch (AppException ae) {
            JOptionPane.showMessageDialog(this, ae.toString(), "Notice",  JOptionPane.PLAIN_MESSAGE);
        }
    }
}//GEN-LAST:event_SaveButtonActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed

private void FindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FindButtonActionPerformed
// FIND BUTTON    
    ClientSsnTextField.setEditable(false);  //prevent editing of SSN in form
    String ssn = findSsnTextField.getText();
    Client client;
    try {
        client = Database.selectClient(ssn);
        
        if (client == null ) {
            JOptionPane.showMessageDialog(this, "Client not found", "Notice",  JOptionPane.PLAIN_MESSAGE);
            //GeneralDialog dialog =  new GeneralDialog(getParent().getParent(), true);
            //dialog.setMessage("help!");
        }
        else {
            //populate form
            ClientSsnTextField.setText(client.CLIENTSSN);	
            FirstNameTextField.setText(client.FIRSTNAME);	
            MiddleInitTextField.setText(client.MIDDLEINIT);
            LastNameTextField.setText(client.LASTNAME);		
            StreetTextField.setText(client.STREET);		
            CityTextField.setText(client.CITY);			
            StateTextField.setText(client.STATE);		
            PhoneTextField.setText(client.PHONE);		
            SexTextField.setText(client.SEX);		
            EmailTextField.setText(client.EMAIL);		
            ZipcodeTextField.setText(client.ZIPCODE);

            ClientSsnTextField.setEditable(false);  //prevent editing of SSN in form

            //get associated records *****
            loadInsuranceTable(ssn);
            loadScheduledVisitsTable(ssn);
            
            
            
        }  //else
    } catch (AppException ae) {
            JOptionPane.showMessageDialog(this, ae.toString(), "Notice",  JOptionPane.PLAIN_MESSAGE);
    }
    
 
  
}//GEN-LAST:event_FindButtonActionPerformed

private void loadScheduledVisitsTable(String ssn) throws AppException {

    final ArrayList<ScheduledVisit> alScheduledVisit = Database.selectScheduledVisitsForClient(ssn);
    //ArrayList<Insured> alInsured = Database.selectInsuranceForClient(ssn);

    TableModel scheduledVisitDataModel = new AbstractTableModel() {
        final int DATE = 0;
        final int LASTNAME = 1;
        final int CAREGIVERID = 2;
        final int TYPEOFCARE = 3;
        final int INVOICE = 4;

        public int getColumnCount() { return 5; }
        public int getRowCount() { return alScheduledVisit.size();}
        public Object getValueAt(int row, int col) { 
            Object data;
            switch (col) {
                case DATE:          data = alScheduledVisit.get(row).DATEOFVISIT;  break;
                case LASTNAME:      data = alScheduledVisit.get(row).careGiver.LASTNAME;   break;
                case CAREGIVERID:   data = alScheduledVisit.get(row).CAREGIVERID;   break;
                case TYPEOFCARE:    data = alScheduledVisit.get(row).TYPEOFCARE;  break;
                case INVOICE:       data = alScheduledVisit.get(row).INVOICENUMBER;  break;
                default:            data = "[invalid]";
            }
            return data;
        }  //getValueAt  
        public String getColumnName(int col) {
            String data;
            switch (col) {
                case DATE:          data = "Date";  break;
                case LASTNAME:      data = "CG Name";   break;
                case CAREGIVERID:   data = "CG ID";   break;
                case TYPEOFCARE:    data = "Care Type";  break;
                case INVOICE:       data = "Invoice";  break;
                default:            data = "[invalid]";
            }
            return data;
        }
    };  //abstracTableModel

    ScheduledVisitsTable.setModel(scheduledVisitDataModel);
}

private void loadInsuranceTable(String ssn) throws AppException   {

    final ArrayList<Insured> alInsured = Database.selectInsuranceForClient(ssn);    //ArrayList<Insured> alInsured = Database.selectInsuranceForClient(ssn);

    TableModel insuranceDataModel = new AbstractTableModel() {
        final int INSURANCE = 0;
        final int ACCOUNT = 1;
        final int ISPRIMARY = 2;
        final int CASEWORKER = 3;
        final int PHONE = 4;

        public int getColumnCount() { return 5; }
        public int getRowCount() { return alInsured.size();}
        public Object getValueAt(int row, int col) { 
            Object data;
            switch (col) {
                case INSURANCE:     data = alInsured.get(row).caseWorker.NAMEOFINSURER;  break;
                case ACCOUNT:       data = alInsured.get(row).INSURANCENUMBER;  break;
                case ISPRIMARY:     data = alInsured.get(row).ISPRIMARY;  break;
                case CASEWORKER:    data = alInsured.get(row).caseWorker.LASTNAME;   break;
                case PHONE:         data = alInsured.get(row).caseWorker.PHONE;   break;
                default:            data = "[invalid]";
            }
            return data;
        }  //getValueAt  
        public String getColumnName(int col) {
            String data;
            switch (col) {
                case INSURANCE:     data = "Insurance";  break;
                case ACCOUNT:       data = "Account #";   break;
                case ISPRIMARY:     data = "Primary";    break;
                case CASEWORKER:    data = "Case Worker";   break;
                case PHONE:         data = "Phone";  break;
                default:            data = "[invalid]";
            }
            return data;
        }
    };  //abstracTableModel

    InsuranceTable.setModel(insuranceDataModel);
}


private void AddInsuranceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddInsuranceActionPerformed
// TODO add your handling code here:
     if (InsuranceDialog == null) {
            //JFrame mainFrame = getApplication().getMainFrame();
            //aboutBox = new NewJFrame();   //mainFrame);  //, true);   //NewJPanel
            InsuranceDialog = new InsuranceDialog();
            //InsuranceDialog.setLocationRelativeTo(this);
            //InsuranceDialog.setVisible(true);
    }
}//GEN-LAST:event_AddInsuranceActionPerformed

private void viewInsuranceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewInsuranceActionPerformed
// TODO add your handling code here:
     if (InsuranceDialog == null) {
            //JFrame mainFrame = getApplication().getMainFrame();
            //aboutBox = new NewJFrame();   //mainFrame);  //, true);   //NewJPanel
            InsuranceDialog = new InsuranceDialog();
            //InsuranceDialog.setLocationRelativeTo(this);
            //InsuranceDialog.setVisible(true);
}//GEN-LAST:event_viewInsuranceActionPerformed
}

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton9ActionPerformed

private void ZipcodeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ZipcodeTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ZipcodeTextFieldActionPerformed

private void findSsnTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findSsnTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_findSsnTextFieldActionPerformed

private void CreateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateButtonActionPerformed
// TODO add your handling code here:
    //clear the form
    ClientSsnTextField.setText("");  //copy data over??
    FirstNameTextField.setText("");	
    MiddleInitTextField.setText("");
    LastNameTextField.setText("");	
    StreetTextField.setText("");	
    CityTextField.setText("");		
    StateTextField.setText("");		
    PhoneTextField.setText("");
    SexTextField.setText("");		
    EmailTextField.setText("");		
    ZipcodeTextField.setText("");
    //make SSN editable
    ClientSsnTextField.setEditable(true);
    
}//GEN-LAST:event_CreateButtonActionPerformed

private void ClientSsnTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClientSsnTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ClientSsnTextFieldActionPerformed

private void FirstNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FirstNameTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_FirstNameTextFieldActionPerformed

private void MiddleInitTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MiddleInitTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_MiddleInitTextFieldActionPerformed

private void LastNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LastNameTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_LastNameTextFieldActionPerformed

private void StreetTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StreetTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_StreetTextFieldActionPerformed

private void CityTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CityTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_CityTextFieldActionPerformed

private void StateTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StateTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_StateTextFieldActionPerformed

private void SexTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SexTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_SexTextFieldActionPerformed

private void EmailTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EmailTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_EmailTextFieldActionPerformed

private void PhoneTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PhoneTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_PhoneTextFieldActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddInsurance;
    private javax.swing.JTextField CityTextField;
    private javax.swing.JTextField ClientSsnTextField;
    private javax.swing.JButton CreateButton;
    private javax.swing.JTextField EmailTextField;
    private javax.swing.JButton FindButton;
    private javax.swing.JTextField FirstNameTextField;
    private javax.swing.JTable InsuranceTable;
    private javax.swing.JTextField LastNameTextField;
    private javax.swing.JTextField MiddleInitTextField;
    private javax.swing.JTextField PhoneTextField;
    private javax.swing.JButton SaveButton;
    private javax.swing.JTable ScheduledVisitsTable;
    private javax.swing.JTextField SexTextField;
    private javax.swing.JTextField StateTextField;
    private javax.swing.JTextField StreetTextField;
    private javax.swing.JTextField ZipcodeTextField;
    private java.awt.Choice choice1;
    private javax.swing.JTextField findSsnTextField;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton viewInsurance;
    // End of variables declaration//GEN-END:variables

    private JDialog InsuranceDialog;
}
